<?php if (defined("YTDJ") or die()); 

// function to scan dirs (php < 5)
if(!function_exists('scandir')) {
    function scandir($dir, $sortorder = 0) {
        if(is_dir($dir) && $dirlist = @opendir($dir)) {
            while(($file = readdir($dirlist)) !== false) {
                $files[] = $file;
            }
            closedir($dirlist);
            ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort
            return $files;
        } else return false;
    }
}

function includeClasses() {	
	// look for php files in classes directory
	$includes = scandir('classes');
	foreach ($includes as $file) {
		if (substr($file,-4,4) == ".php") {
			include_once('classes/'.$file);
		}
	}
}

function __autoload($classname) {
	$file = "classes/".strtolower($classname).".php";
	if (file_exists($file)) {
		include $file;
	} else {
		//throw new Exception("Failed to autoload class $classname");
		return false;
	}
}

if (get_magic_quotes_gpc()) {
	$in = array(&$_GET, &$_POST, &$_COOKIE);
	while (list($k,$v) = each($in)) {
		foreach ($v as $key => $val) {
			if (!is_array($val)) {
				$in[$k][$key] = stripslashes($val);
				continue;
			}
				$in[] =& $in[$k][$key];
			}
		}
	unset($in);
}
?>